"use strict";

exports.__esModule = true;
var ary = exports.ary = function ary(fn, n) {
    return function () {
        for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
            args[_key] = arguments[_key];
        }

        return fn.apply(undefined, args.slice(0, n));
    };
};

var call = exports.call = function call(key) {
    for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
        args[_key2 - 1] = arguments[_key2];
    }

    return function (context) {
        return context[key].apply(context, args);
    };
};

var collectInto = exports.collectInto = function collectInto(fn) {
    return function () {
        for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
            args[_key3] = arguments[_key3];
        }

        return fn(args);
    };
};

var flip = exports.flip = function flip(fn) {
    return function (first) {
        for (var _len4 = arguments.length, rest = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
            rest[_key4 - 1] = arguments[_key4];
        }

        return fn.apply(undefined, rest.concat([first]));
    };
};

var over = exports.over = function over() {
    for (var _len5 = arguments.length, fns = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
        fns[_key5] = arguments[_key5];
    }

    return function () {
        for (var _len6 = arguments.length, args = Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
            args[_key6] = arguments[_key6];
        }

        return fns.map(function (fn) {
            return fn.apply(null, args);
        });
    };
};

var overArgs = exports.overArgs = function overArgs(fn, transforms) {
    return function () {
        for (var _len7 = arguments.length, args = Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
            args[_key7] = arguments[_key7];
        }

        return fn.apply(undefined, args.map(function (val, i) {
            return transforms[i](val);
        }));
    };
};

var pipeAsyncFunctions = exports.pipeAsyncFunctions = function pipeAsyncFunctions() {
    for (var _len8 = arguments.length, fns = Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
        fns[_key8] = arguments[_key8];
    }

    return function (arg) {
        return fns.reduce(function (p, f) {
            return p.then(f);
        }, Promise.resolve(arg));
    };
};

var promisify = exports.promisify = function promisify(func) {
    return function () {
        for (var _len9 = arguments.length, args = Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
            args[_key9] = arguments[_key9];
        }

        return new Promise(function (resolve, reject) {
            return func.apply(undefined, args.concat([function (err, result) {
                return err ? reject(err) : resolve(result);
            }]));
        });
    };
};

var rearg = exports.rearg = function rearg(fn, indexes) {
    return function () {
        for (var _len10 = arguments.length, args = Array(_len10), _key10 = 0; _key10 < _len10; _key10++) {
            args[_key10] = arguments[_key10];
        }

        return fn.apply(undefined, args.reduce(function (acc, val, i) {
            return acc[indexes.indexOf(i)] = val, acc;
        }, Array.from({ length: indexes.length })));
    };
};